package com.jrzh.mvc.service.sys.impl;

import java.io.Serializable;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.jrzh.common.exception.ProjectException;
import com.jrzh.framework.base.convert.BaseConvertI;
import com.jrzh.framework.base.repository.BaseRepository;
import com.jrzh.framework.base.service.impl.BaseServiceImpl;
import com.jrzh.mvc.convert.sys.FileRuleConvert;
import com.jrzh.mvc.repository.sys.FileRuleRepository;
import com.jrzh.mvc.model.sys.FileRuleModel;
import com.jrzh.mvc.search.sys.FileRuleSearch;
import com.jrzh.mvc.search.sys.FileSearch;
import com.jrzh.mvc.service.sys.FileRuleServiceI;
import com.jrzh.mvc.service.sys.manage.SysServiceManage;
import com.jrzh.mvc.view.sys.FileRuleView;

@Service("fileRuleService")
public class FileRuleServiceImpl extends
		BaseServiceImpl<FileRuleModel, FileRuleSearch, FileRuleView> implements
		FileRuleServiceI {

	@Autowired
	private FileRuleRepository fileRuleRepository;
	
	@Autowired
	private SysServiceManage sysServiceManage;

	@Override
	public BaseRepository<FileRuleModel,Serializable> getDao() {
		return fileRuleRepository;
	}

	@Override
	public BaseConvertI<FileRuleModel, FileRuleView> getConvert() {
		return new FileRuleConvert();
	}
	
	@Override
	public List<FileRuleView> viewListAndCount(FileRuleSearch search,String formId) throws ProjectException{
		List<FileRuleView> fileRulesList = this.viewList(search);
		for(FileRuleView fileRule : fileRulesList){
			FileSearch fileSearch = new FileSearch();
			fileSearch.setEqKey(fileRule.getKey());
			fileSearch.setEqualFormId(formId);
			Long count = sysServiceManage.fileService.count(fileSearch);
			fileRule.setCount(count);
		}
		return fileRulesList;
	}
}
